package com.jk.util.autotest;

import com.jk.util.autotest.model.InterfaceTestInfo;
import com.jk.util.autotest.util.HttpUtilPlus;

import static com.jk.util.autotest.util.JsonUtil.getTl;

/**
 * @author Administrator
 */
public class TestThread extends Thread {

    String name;
    String path;
    String data;
    Long tl;

    public TestThread(String name,String path,String data){
        this.name = name;
        this.path = path;
        this.data = data;
    }

    @Override
    public void run() {
        while (true){
            System.out.println(name);
            String json = HttpUtilPlus.interfaceUtil(path,data,false);
            if(tl != null && !tl.equals(getTl(json))){
                Main.count();

                InterfaceTestInfo interfaceTestInfo = new InterfaceTestInfo();
                interfaceTestInfo.setName(name);
                interfaceTestInfo.setAddress(path);
                interfaceTestInfo.setSaveTime(getTl(json)-tl);
                if(Math.abs(interfaceTestInfo.getSaveTime()-180)>5){
                    if(interfaceTestInfo.getSaveTime()<3){
                        interfaceTestInfo.setConclusion("每次走数据库");
                    }else {
                        interfaceTestInfo.setConclusion("异常");
                    }
                }else {
                    interfaceTestInfo.setConclusion("正常");
                }
                Main.interfaceTestInfos.add(interfaceTestInfo);
                break;
            }
            tl = getTl(json);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
